package bestTeam.WalkieDoggie.server;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bestTeam.WalkieDoggie.client.walkieStatus;
import bestTeam.WalkieDoggie.client.Serializables.UserRequest;

import com.google.gwt.core.client.JsonUtils;

public class NotifyWithoutImageServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {

		String owner = req.getParameter("owner_name");
		String owner_email = req.getParameter("owner_email");
		String walker = req.getParameter("walker");
		String requestID = req.getParameter("requestID");

		sendApprovementEmail(owner,owner_email,walker);
		
		RequestServiceImpl requestService = new RequestServiceImpl();
		UserRequest request = requestService.getRequest(requestID);
		request.setStatus(walkieStatus.EXPIRED);
		requestService.UpdateRequest(request);
		
		resp.getWriter().println("approvement email sent successfuly to "+owner+"!");
	}

	private void sendApprovementEmail(String owner, String owner_email,String walker) {
		EmailServiceImpl emailService = new EmailServiceImpl();

		String header = "Hi "+owner+"! Your dog got his walk!";
		String body = "Hi "+owner+"!\n\n"+walker+" has just notified that your dog got his walk!\n\n\n\nHave a nice day!";
		emailService.sendEmail(owner_email,header,body);

		
	}


	
	
}